package com.cssy.xxkj.logic.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.cssy.xxkj.logic.dao.LogicWarehouseInventoryDAO;
import com.cssy.xxkj.logic.entity.LogicWarehouseInventoryDO;
import com.cssy.xxkj.logic.entity.vo.LogicMaterialBackBillTypeSelVO;
import com.cssy.xxkj.logic.entity.vo.LogicWarehouseEndMonthSumVO;
import com.cssy.xxkj.logic.entity.vo.LogicWarehouseInventoryVO;
import com.plat.exception.SyBaseException;
import com.plat.helper.SearchConditions;

/**
 * 数据访问对象实现类
 * @since 2014-09-16
 */
public class LogicWarehouseInventoryDAOImpl extends SqlMapClientDaoSupport implements LogicWarehouseInventoryDAO {

    /**
     * 插入数据
     * @param logicWarehouseInventoryDO
     * @return 插入数据的主键
     */
    public String insertLogicWarehouseInventoryDO(LogicWarehouseInventoryDO logicWarehouseInventoryDO) {
        Object id = getSqlMapClientTemplate().insert("LogicWarehouseInventory.insert", logicWarehouseInventoryDO);
        return (String) id;
    }

    /**
     * 统计记录数
     * @param logicWarehouseInventoryDO
     * @return 查出的记录数
     */
    public Integer countLogicWarehouseInventoryDOByExample(LogicWarehouseInventoryDO logicWarehouseInventoryDO) {
        Integer count = (Integer) getSqlMapClientTemplate().queryForObject("LogicWarehouseInventory.countByDOExample", logicWarehouseInventoryDO);
        return count;
    }

    /**
     * 更新记录
     * @param logicWarehouseInventoryDO
     * @return 受影响的行数
     */
    public Integer updateLogicWarehouseInventoryDO(LogicWarehouseInventoryDO logicWarehouseInventoryDO) {
        int result = getSqlMapClientTemplate().update("LogicWarehouseInventory.update", logicWarehouseInventoryDO);
        return result;
    }

    /**
     * 获取对象列表
     * @param logicWarehouseInventoryDO
     * @return 对象列表
     */
    @SuppressWarnings("unchecked")
    public List<LogicWarehouseInventoryDO> findListByExample(LogicWarehouseInventoryDO logicWarehouseInventoryDO) {
        List<LogicWarehouseInventoryDO> list = getSqlMapClientTemplate().queryForList("LogicWarehouseInventory.findListByDO", logicWarehouseInventoryDO);
        return list;
    }

    /**
     * 根据主键获取logicWarehouseInventoryDO
     * @param id
     * @return logicWarehouseInventoryDO
     */
    public LogicWarehouseInventoryDO findLogicWarehouseInventoryDOByPrimaryKey(String id) {
        LogicWarehouseInventoryDO logicWarehouseInventoryDO = (LogicWarehouseInventoryDO) getSqlMapClientTemplate().queryForObject("LogicWarehouseInventory.findByPrimaryKey", id);
        return logicWarehouseInventoryDO;
    }

    /**
     * 删除记录
     * @param id
     * @return 受影响的行数
     */
    public Integer deleteLogicWarehouseInventoryDOByPrimaryKey(String id) {
        Integer rows = (Integer) getSqlMapClientTemplate().delete("LogicWarehouseInventory.deleteByPrimaryKey", id);
        return rows;
    }

	public List<LogicWarehouseInventoryDO> find(SearchConditions scs) throws DataAccessException {
		List<LogicWarehouseInventoryDO> list = getSqlMapClientTemplate().queryForList("LogicWarehouseInventory_ex.find", scs);
        return list;
	}

	public Integer count(SearchConditions scs) throws DataAccessException {
		Integer count = (Integer) getSqlMapClientTemplate().queryForObject("LogicWarehouseInventory_ex.count", scs);
        return count;
	}

	public Integer deleteBizRemoved(String id) throws DataAccessException {
		Integer count = (Integer) getSqlMapClientTemplate().queryForObject("LogicWarehouseInventory_ex.deleteBizRemoved", id);
        return count;
	}

	public List<LogicWarehouseInventoryVO> findForWareHouseStock(SearchConditions scs)
			throws DataAccessException {
		List<LogicWarehouseInventoryVO> list = getSqlMapClientTemplate().queryForList("LogicWarehouseInventory_ex.findListBySearchConForWareHouseStock", scs);
		return list;
	}

	public Integer findForWareHouseStockCount(SearchConditions scs)
			throws DataAccessException {
		Integer count = (Integer) getSqlMapClientTemplate().queryForObject("LogicWarehouseInventory_ex.findListBySearchConForWareHouseStockCount", scs);
		return count;
	}
	
	public List<LogicWarehouseInventoryDO> findWareHouseStockByMap(Map<String, Object> paramMap)throws DataAccessException{
		List<LogicWarehouseInventoryDO> list = getSqlMapClientTemplate().queryForList("LogicWarehouseInventory_ex.findWareHouseStockByMap", paramMap);
		return list;
	}
	
	//退货时入库单选择
	public List<LogicMaterialBackBillTypeSelVO> findSingleStockToBackSel(SearchConditions scs)throws DataAccessException{
		List<LogicMaterialBackBillTypeSelVO> list = getSqlMapClientTemplate().queryForList("LogicWarehouseInventory_ex.findSingleStockToBackSel", scs);
		return list;
	}
	
	public Integer countSingleStockToBackSel(SearchConditions scs) throws DataAccessException {
		Integer count = (Integer) getSqlMapClientTemplate().queryForObject("LogicWarehouseInventory_ex.countSingleStockToBackSel", scs);
        return count;
	}

	@Override
	public Integer deleteWarehouseInventoryByMap(Map<String, Object> paramMap)
			throws SyBaseException {
		return (Integer) getSqlMapClientTemplate().delete("LogicWarehouseInventory_ex.deleteWarehouseInventoryByMap", paramMap);
	}
	
	@Override
	public List<LogicWarehouseEndMonthSumVO> findQueryEndMonthToSummary(SearchConditions scs)throws SyBaseException{
		List<LogicWarehouseEndMonthSumVO> list = getSqlMapClientTemplate().queryForList("LogicWarehouseInventory_ex.findQueryEndMonthToSummary", scs);
		return list;
	}
}